package com.ruoyi.project.config;

import com.aliyun.oss.OSSClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * com.ruoyi.project.config.AliyunOSSCoreConfig
 * <br>
 *
 * @author 蒋カイセキ    Japan-Tokyo  19-3-8 上午10:31<br>
 * ブログ http://www.shoukaiseki.top/<br>
 * E-メール jiang28555@Gmail.com<br>
 **/
@Component
@EnableConfigurationProperties(AliyunOSSCoreProperties.class)
public class AliyunOSSCoreConfig {

    @Resource
    AliyunOSSCoreProperties aliyunOSSCoreProperties;

    /**
     * 线程安全对象,单利模式即可,不需要 shutdown
     */
    @Bean
    public OSSClient ossClient(){
        OSSClient ossClient=null;
        try {
            ossClient = new OSSClient(aliyunOSSCoreProperties.getEndpoint(), aliyunOSSCoreProperties.getAccessKeyId(), aliyunOSSCoreProperties.getSecretAccessKey());
        }catch (Exception e){
            e.printStackTrace();
            ossClient =new OSSClient("xx","xx","xx");
        }
        return ossClient;
    }
}
